/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package engineJess;

import generateCLP.CLPWriter;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import jess.JessException;
import jess.Rete;
import jess.awt.TextReader;
import jess.swing.JTextAreaWriter;

/**
 *
 * @author Danzz
 */
public class engineThread extends Thread {
    public Rete engine;
    JTextAreaWriter taw;
    TextReader tr;
    boolean done = false;
    
    public engineThread (JTextArea jTextArea1) throws JessException {
        this.engine = new Rete();
        taw = new JTextAreaWriter(jTextArea1);
        tr = new TextReader(false);
        engine.addInputRouter("t", tr, true);
        engine.addOutputRouter("t", taw);
        engine.addInputRouter("WSTDIN", tr, true);
        engine.addOutputRouter("WSTDOUT", taw);
        engine.addOutputRouter("WSTDERR", taw);
    }
    
    public void batchFileCLP(String fileCLP) throws JessException{
        engine.batch(fileCLP);
    }
    
    public void addInput(String t) {
        tr.appendText(t+"\n");
    }
    
    public void evalAllFacts(String a) throws JessException {
        engine.eval(a);
        engine.reset();
    }
    
     public void callJessFile() {
        try {
            engine.run();
            done = true;
        } catch (JessException je) {
            je.printStackTrace();
        }
    }
     
    
    
    public void run() {
        this.callJessFile();
    }
}
